import 'package:black_movice/config/configs.dart';
import 'package:black_movice/utils/Utils.dart';
import 'package:black_movice/views/pages/filter/filter.dart';
import 'package:black_movice/views/pages/index/index.dart';
import 'package:black_movice/views/pages/popularize/popularize.dart';
import 'package:black_movice/views/pages/user/user.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:responsive_navigation_bar/responsive_navigation_bar.dart';

class Home extends StatefulWidget {
  const Home({super.key});

  @override
  State<Home> createState() => _HomeState();
}

class _HomeState extends State<Home> {
  // 页面控制器
  final PageController _pageController = PageController();

  // 页面索引
  int _pageIndex = 0;
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return PopScope(
      canPop: true,
      onPopInvokedWithResult: (didPop, result) => {},
      child: Scaffold(
        body: AnimatedContainer(
          duration: const Duration(seconds: 1),
          child: PageView(
            controller: _pageController,
            physics: NeverScrollableScrollPhysics(),
            // 要切换的页面
            children: [
              Index(),
              Filter(),
              Popularize(),
              User(),
            ],
          ),
        ),
        bottomNavigationBar: ResponsiveNavigationBar(
          borderRadius: 20.sp,
          activeButtonFlexFactor: 80,
          selectedIndex: _pageIndex,
          outerPadding: const EdgeInsets.fromLTRB(5, 0, 5, 5),
          fontSize: Configs.lgTitleSize_16,
          textStyle: TextStyle(
            color: Colors.white,
          ),
          navigationBarButtons: <NavigationBarButton>[
            NavigationBarButton(
              text: '首页',
              icon: Icons.home,
              backgroundColor: Colors.lightBlueAccent,
            ),
            NavigationBarButton(
              text: '筛选',
              icon: Icons.filter_list,
              backgroundColor: Colors.lightBlueAccent,
            ),
            NavigationBarButton(
              text: '推广',
              icon: Icons.screen_share,
              backgroundColor: Colors.lightBlueAccent,
            ),
            NavigationBarButton(
              text: '我的',
              icon: Icons.people,
              backgroundColor: Colors.lightBlueAccent,
            ),
          ],
          onTabChange: (value) {
            setState(() {
              _pageIndex = value;
            });
            _pageController.jumpToPage(_pageIndex);
            Utils.logDebug(_pageIndex);
          },
        ),
      ),
    );
  }
}
